package com.pl.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pl.entity.Repairstatus;
import com.pl.service.RepairstatusService;
import com.pl.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/api/status")
public class RepairstatusController {
    @Autowired
    private RepairstatusService repairstatusService;
    @PostMapping("/save")
    public R add(Repairstatus repairstatus){
        int i = repairstatusService.add(repairstatus);
        if(i>0){
            return R.ok("success");
        }
        return R.fail("fail");
    }
    @DeleteMapping("/del/{statusId}")
    public R deleteById(@PathVariable Integer statusId){
        int i = repairstatusService.deleteById(statusId);
        if(i>0){
            return R.ok("success");
        }
      return R.fail("fail");
    }
    @PostMapping("/edit")
    public R updateById(Repairstatus repairstatus){
        int i = repairstatusService.updateById(repairstatus);
        if(i>0){
            return R.ok("success");
        }
        return R.fail("fail");
    }
    @PostMapping("/list/page1")
    public R findByMap(int pageNum, int pageSize,@RequestParam HashMap<String,Object> map){
        PageHelper.startPage(pageNum,pageSize);
        List<Repairstatus> byMap = repairstatusService.findByMap(map);
        System.out.println(byMap);
        PageInfo<Repairstatus> pageInfo = new PageInfo<>(byMap);
        return R.ok(pageInfo);
    }
    @PostMapping("/del/batch")
    public R deleteByList(@RequestParam List<Integer> list){
        int i = repairstatusService.deleteByList(list);
        if(i>0){
            return R.ok("success");
        }
        return R.fail("fail");
    }
}
